<?php
class MHDEV_View_Helper_GetRating extends Zend_View_Helper_Abstract
{
	/*
	 * Get the rating of a post
	 * 
	 * @param int $uid
	 * @param string $mode
	 * 
	 * @return int value
	 */
	public function GetRating($uid, $mode = FALSE)
	{
		// db
		$rates	= new Rates();
		
		// query
		if($mode)
		{
			$rating		= $rates->fetchAll('post_uid = ' . $uid . ' AND value = "' . $mode . '"');
			$content	= $rating->count();
		}
		else
		{
			$rate_up	= $rates->fetchAll('post_uid = ' . $uid . ' AND value = "up"');
			$up_count	= $rate_up->count();
			
			$rate_down	= $rates->fetchAll('post_uid = ' . $uid . ' AND value = "down"');
			$down_count	= $rate_down->count();
			
			$content	= $up_count-$down_count;
		}
		
		return $content;
	}
}